package br.com.evoluy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import br.com.evoluy.controle.Facade;
import br.com.evoluy.entidade.LogAcesso;
import br.com.evoluy.entidade.Usuario;
import br.com.evoluy.util.TimeStamp;


@WebServlet("/Ssair")
public class Ssair extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public Ssair() {
        super();
      
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession sessao = (HttpSession) request.getSession();
		Usuario usuario = (Usuario) sessao.getAttribute("Usuario");
		TimeStamp time = new TimeStamp();
		
		LogAcesso logacesso = new LogAcesso();
		logacesso.setNomeusuario(usuario.getNome());
		logacesso.setSobrenome(usuario.getSobrenome());
		logacesso.setIdusuario(usuario.getId());
		logacesso.setSenha(usuario.getSenha());
		logacesso.setPsf(usuario.getPsf());
		logacesso.setTipoacesso("saida");
		logacesso.setTimestamp(time.timeStamp());
		
		try 
		{
			Facade.getInstance().getControleLogAcesso().logdeAcesso(logacesso);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
			
		response.sendRedirect("login.jsp");
		sessao.invalidate();
	}

}
